using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using BUS;
using Utility;
using Encosia;

public partial class PH_KH_home_phkh : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["Page"] = mainmenu.loaisp;

        if (!IsPostBack && Session["idRedirecttinhthanh"].ToString() == "")
        {
            loadsp();
        }
        if (Session["idRedirecttinhthanh"].ToString() != "")
        {
            LoadData();
        }
        //if (Session["loai"].ToString() != "")
        //{
        //    LoadData1();
        //}
    }

    private void LoadData1()
    {
        int id = int.Parse(Request.QueryString["id"].ToString());
        try
        {
            rep_tinhthanh.DataSource = tbsanphamBUS.getloai(id);
            rep_tinhthanh.DataBind();
        }
        catch
        {
            Response.Redirect("~/trangchinh.aspx");
        }
    }

    private void loadsp()
    {
        rep_tinhthanh.DataSource = tbsanphamBUS.GETAll();
        rep_tinhthanh.DataBind();
    }

    private void LoadData()
    {
        int id = int.Parse(Session["idRedirecttinhthanh"].ToString());

        try
        {
            rep_tinhthanh.DataSource = tbsanphamBUS.getidtinhthanh(id);
            rep_tinhthanh.DataBind();

        }
        catch
        {
            Response.Redirect("home_phkh.aspx");
        }
    }
    protected void rep_tinhthanh_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem ||
        e.Item.ItemType == ListItemType.Item)
            {
                tbsanphamDTO sanpham = (tbsanphamDTO)e.Item.DataItem;

                HyperLink lit_TenSp = (HyperLink)e.Item.FindControl("lit_TenSp");
                lit_TenSp.NavigateUrl = "chitietsp.aspx?id=" + sanpham.Masp.ToString();
                lit_TenSp.Text = sanpham.Tensp;
                Literal mota = (Literal)e.Item.FindControl("lit_mota");
                if (sanpham.Dacdiem.Length > 20)
                    mota.Text = sanpham.Dacdiem.Substring(0, 50) + "...";
                else
                    mota.Text = sanpham.Dacdiem;

                HighslideImage hinh = (HighslideImage)e.Item.FindControl("img_hinh");
                tbhinhanhDTOColection hinhanh = tbhinhanhBUS.getid(sanpham.Masp);


                hinh.ImageUrl = "~/Admin/image/hinhnho/" + hinhanh[0].Tenhinhanh;
                hinh.FullImageURL = "~/Admin/image/thump/" + hinhanh[0].Tenhinhanh;
            }
        }
        catch
        {
            loadsp();

        }
    }
}
